package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.example.demo.po.About;
import com.example.demo.service.AboutService;

@Controller
@RequestMapping("/admin")
public class AdminAboutController {
	
	@Autowired	
	private AboutService aboutService;
	
	@RequestMapping(value="/adminAbout.action",method=RequestMethod.GET)
	public String indext(Model model){
		
		List<About> aboutList = aboutService.selectAll();
		
		model.addAttribute("aboutList", aboutList); 
		
		return "admin/about/aboutList";
		
	}
	
	@RequestMapping(value="/toEditAbout.action",method=RequestMethod.GET)
	public String toEdit(Model model,Integer id){
		
		if(id!=null){
			
			About about=aboutService.selectById(id);
			
			model.addAttribute("about", about);
		}
		
		return "admin/about/edit";
		
	}
	
	@RequestMapping(value="/editAbout.action",method=RequestMethod.POST)
	public String edit(About about){
		
		if(about.getId()!=null){
			aboutService.update(about);
		}else{
			aboutService.insert(about);
		}
		
		return "redirect:adminAbout.action";		
	}
	
	@RequestMapping(value="/deleteAbout.action",method=RequestMethod.GET)
	public String delete(Integer id){
		
		aboutService.delete(id);
		return "redirect:adminAbout.action";
		
	}

}
